import happybase
from collections import Counter


table_name = 'house-table'
connection = happybase.Connection('hbase-docker', 9090)
table = connection.table(table_name)

def format_row(d):
    val = d.values()
    val = map(lambda x: x.decode(), val)
    val = list(val)
    return val

def bdict_dict(bd):
    return {key.decode(): val.decode() for key, val in bd.items()}

i = 0
f = open('data.csv', 'w')
# for key, val in table.scan(row_prefix='高新园区'.encode()):
#     print(key.decode())
#     print(bdict_dict(val))
# a = table.scan(row_prefix='高新园区'.encode())
# b = next(a)[1]
# print(b)
# print(b[b'family:band'].decode())
# exit(0)

def getanlydata(kind, arae):
    a = map(lambda x: x[1][kind].decode(), table.scan(row_prefix=arae.encode()))
    b = Counter(a)
    newdict = {}
    return [{'name':key, 'value': val} for key, val in b.items()]

print(getanlydata(b'family:room', '高新园区'))

f.close()
connection.close()


